//-------------------------------------------------------------------------------------------//
// Copyright(c) Wang Yong
// Author     : Wang Yong
// Date       : 2021-06-01
// Description: Refine the triangle mesh by split the marked element. It is designed for
// MoM adaptive mesh function.
//-------------------------------------------------------------------------------------------//
#ifndef TRIA_MESH_REFINE_H
#define TRIA_MESH_REFINE_H
#include "MeshRefine.h"

using namespace Mesher;

class RefineTria
{
public:
    RefineTria() = default;
    ~RefineTria() = default;
    // find all common edge
    void fn_FindTriaEdges(std::vector<Node> &vR, std::vector<Tria> &vElem);
    // mark the edges need to be splitted
    void fn_MarkSplitEdge(std::vector<Tria> &vElem, std::vector<bool> &vRefine);
    // adapt the edge to improve the mesh quality
    void fn_AdaptTriaEdge(std::vector<Tria> &vElem);
    // insert new point on each edge
    void fn_AddEdgesPoint(std::vector<Tria> &vElem, std::vector<Node> &vR);
    // split each element
    void fn_SplitEachTria(std::vector<Tria> &vElem);

private:
    std::vector<std::vector<int>> m_vTriaEdge;
    std::vector<Real> m_vEdgeLen;
    std::vector<bool> m_vEdgeFlag;
    std::vector<int>  m_vEdgeNode;

    // split only one triangle edge
    void fn_SplitEdge1(Tria &oldTria, std::vector<int> &vEdgeIndx, std::vector<Tria> &vNewTria);
    // split two triangle edges
    void fn_SplitEdge2(Tria &oldTria, std::vector<int> &vEdgeIndx, std::vector<Tria> &vNewTria);
    // split all three triangle edges
    void fn_SplitEdge3(Tria &oldTria, std::vector<int> &vEdgeIndx, std::vector<Tria> &vNewTria);
};

#endif

